package com.zsjp.alc.service.impl;

import java.util.List;

import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zsjp.alc.constant.ZsjpErrorCode;
import com.zsjp.alc.dao.PersonInfoDao;
import com.zsjp.alc.entity.PersonInfo;
import com.zsjp.alc.enums.PersonInfoStateEnum;
import com.zsjp.alc.exception.ZsjpException;
import com.zsjp.alc.restresult.PersonInfoExecution;
import com.zsjp.alc.restresult.ZsjpResponseResult;
import com.zsjp.alc.service.PersonInfoService;
import com.zsjp.alc.utils.PageCalculator;

@Service
public class PersonInfoServiceImpl implements PersonInfoService {
	@Autowired
	private PersonInfoDao personInfoDao;

	@Override
	public PersonInfo getPersonInfoById(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PersonInfoExecution getPersonInfoList(PersonInfo personInfoCondition, int pageIndex, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PersonInfoExecution addPersonInfo(PersonInfo personInfo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PersonInfoExecution modifyPersonInfo(PersonInfo personInfo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ZsjpResponseResult checkSuperAdmin(PersonInfo personInfo) {
		ZsjpResponseResult result = new ZsjpResponseResult("0");
		String name = personInfo.getName();
		String password = personInfo.getPassword();
		if((name == null && password == null)
				|| ("".equals(name) && "".equals(password))){
			throw new ZsjpException(ZsjpErrorCode.NAME_PASSWORD_ERROR_10000003);
		}
		
		String realPassword = personInfoDao.querySuperAdminPasswordByName(name);
		if(realPassword == null){
			throw new ZsjpException(ZsjpErrorCode.USERNAME_ERROR_10000002);
		}
		if(realPassword.equals(password)){
			List<PersonInfo> personInfoList = personInfoDao.querySuperAdminByName(name);
			result = new ZsjpResponseResult("0");
			result.setData(personInfoList);
		} else {
			throw new ZsjpException(ZsjpErrorCode.PASSWORD_ERROR_10000001);
		}
		return result;
	}
}
